package com.sdp.lease.controller;


import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.lease.db.l_banner_info.entity.LBannerInfo;
import com.sdp.lease.db.l_banner_info.service.ILBannerInfoService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-07-25
 */
@RestController
@RequestMapping("/LBannerInfoController")
public class LBannerInfoController {

	@Autowired
	private Query query;
	
	@Autowired
	private ILBannerInfoService iLBannerInfoService;
	
	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.page(iLBannerInfoService, LBannerInfo.class, dataCenter));
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody LBannerInfo bannerInfo) {
		if(bannerInfo==null) {
			return Result.error("轮播图信息为空");
		}
		if(StringUtils.isEmpty(bannerInfo.getKeyId())) {
			bannerInfo.setCreateTime(LocalDateTime.now());
			iLBannerInfoService.save(bannerInfo);
		}else {
			iLBannerInfoService.updateById(bannerInfo);
		}
		
		return Result.ok();
	}
}

